'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = (app) => {
  const { router, controller } = app;
  const preRouter = '/api/shop';
  // 引入中间件验证token  需要验证的在路由写入token
  // const authorization = app.middleware.authorization();

  // 获取短信验证码
  router.post(preRouter + '/sms', controller.shop.home.sms);
  // 获取图片验证码
  router.get(preRouter + '/verify', controller.shop.home.verify);
  // 获取城市
  router.get(preRouter + '/city', controller.shop.home.getCity);

  // 用户api ------------------------------------------------------
  // 充钱
  router.post(preRouter + '/user/recharge', controller.shop.user.recharge);
  // 查询余额
  router.get(preRouter + '/user/balance', controller.shop.user.balance);
  router.post(preRouter + '/user/wxlogin', controller.shop.user.wxlogin);
  // 注册
  router.post(preRouter + '/register', controller.shop.user.create);
  // 登录
  router.post(preRouter + '/login', controller.shop.login.login);
  // 退出登录
  router.post(preRouter + '/logout', controller.shop.login.logout);
  // 获取自己的用户信息
  router.get(preRouter + '/user/userInfo', controller.shop.user.userInfo);
  // 获取用户访问量
  router.get(preRouter + '/user/visitnum', controller.shop.user.visitnum);
  // 用户的增删改查
  router.resources('user', preRouter + '/user', controller.shop.user);
  //------------------------------------------------------------------

  //-------------------------------------------------
  // 获取每个分类的商品信息
  router.get(
    preRouter + '/classify/classifyGoods',
    controller.shop.classify.classifyGoods
  );
  // 商品分类curd
  router.resources(
    'classify',
    preRouter + '/classify',
    controller.shop.classify
  );

  // 获取热门商品
  router.get(preRouter + '/goods/hotGoods', controller.shop.goods.hotGoods);
  //获取某类商品的销售数量
  router.get(preRouter + '/goods/getSoldNum', controller.shop.goods.getSoldNum);
  //获取总销售数量
  router.get(preRouter + '/goods/getAllNum', controller.shop.goods.getAllNum);
  // 商品curd

  router.resources('goods', preRouter + '/goods', controller.shop.goods);

  // 商品sku的key与value curd
  router.post(preRouter + '/skuKeyValue', controller.shop.sku.createKeyValue);
  router.get(preRouter + '/getKeyValue', controller.shop.sku.getKeyValue);
  router.delete(
    preRouter + '/delKeyValue/:id',
    controller.shop.sku.delKeyValue
  );
  router.post(
    preRouter + '/updateKeyValue',
    controller.shop.sku.updateKeyValue
  );
  // 商品sku curd
  router.put('sku', preRouter + '/sku/:id', controller.shop.sku.update);
  router.delete('sku', preRouter + '/sku/:id', controller.shop.sku.destroy);
  router.post('sku', preRouter + '/sku', controller.shop.sku.create);
  router.get('sku', preRouter + '/getSku', controller.shop.sku.show);

  router.get('sku', preRouter + '/skuAdmin/:id', controller.shop.sku.adminShow);
  //搜索商品
  router.get(preRouter + '/goodsSearch', controller.shop.goods.search);

  router.get(preRouter + '/goods/getById/:id', controller.shop.goods.getById);
  // 商品规格
  router.resources(
    'specification',
    preRouter + '/specification',
    controller.shop.specification
  );

  // 商品规格属性
  router.resources(
    'specificationAttr',
    preRouter + '/specificationAttr',
    controller.shop.specificationAttr
  );

  // 项目curd
  // router.post(preRouter + '/project/set', controller.shop.project.set);
  // router.resources('project', preRouter + '/project', controller.shop.project);
  // router.get(
  //   preRouter + '/project/getProjectById',
  //   controller.shop.project.getProjectById
  // );

  // 图片
  router.post('photo', preRouter + '/photo', controller.shop.photo.create);
  router.post(preRouter + '/upload/base64', controller.shop.photo.uploadBase64);

  // 上传文件(轮播图)
  router.post(preRouter + '/update', controller.shop.update.index);
  router.post(preRouter + '/updateM', controller.shop.update.multiple);

  // 商品上传文件
  router.post(preRouter + '/imgUpdate', controller.shop.imgUpdate.multiple);

  // 订单 curd
  router.put(preRouter + '/order/:id', controller.shop.order.update);
  router.post(preRouter + '/orderpay', controller.shop.order.pay);
  router.resources('order', preRouter + '/order', controller.shop.order);
  router.get(preRouter + '/ordercount', controller.shop.order.ordercount);

  // 支付订单
  router.get(preRouter + '/wechatpay', controller.shop.wechatpay.get);
  router.post(preRouter + '/wechatpay', controller.shop.wechatpay.create);
  router.delete(preRouter + '/wechatpay', controller.shop.wechatpay.close);
  router.post(
    preRouter + '/wechatpay/refund',
    controller.shop.wechatpay.refund
  );
  router.post(
    preRouter + '/wechatpay/notify',
    controller.shop.wechatpay.notify
  );

  // 购物车 curd
  router.resources(
    'shoppingCart',
    preRouter + '/shoppingCart',
    controller.shop.shoppingCart
  );

  // 轮播图 curd
  // router.resources(
  //   'carousel',
  //   preRouter + '/carousel',
  //   controller.shop.carousel
  // );
  router.post(preRouter + '/carousel/create', controller.shop.carousel.create);
  router.put(
    preRouter + '/carousel/update/:id',
    controller.shop.carousel.update
  );
  router.delete(
    preRouter + '/carousel/delete/:id',
    controller.shop.carousel.destroy
  );
  router.get(preRouter + '/carousel/getAll', controller.shop.carousel.index);
  router.get(preRouter + '/carousel/getById', controller.shop.carousel.show);

  router.post(
    preRouter + '/carouselgroup/create',
    controller.shop.carouselGroup.create
  );
  router.delete(
    preRouter + '/carouselgroup/delete',
    controller.shop.carouselGroup.delete
  );
  router.get(
    preRouter + '/carouselgroup/get',
    controller.shop.carouselGroup.get
  );
  router.get(
    preRouter + '/carouselgroup/:id',
    controller.shop.carouselGroup.show
  );

  // 地址 curd
  router.resources('address', preRouter + '/address', controller.shop.address);
  // 获取默认地址
  router.get(
    preRouter + '/defalutAddress',
    controller.shop.address.defalutAddress
  );
  // 设置默认地址
  router.post(
    preRouter + '/setDefault/:id',
    controller.shop.address.setDefault
  );

  //创建物流信息
  router.post(
    preRouter + '/createLogistics',
    controller.shop.order.createLogistics
  );
  //查看物流信息
  router.get(preRouter + '/getLogistics', controller.shop.order.getLogistics);
};
